<template>
  <tr>
    <td><input type="checkbox" :checked="item.checked" @change="$store.commit('goodlist/UpdateChecked',index)"/></td>
    <td>{{ item.name }}</td>
    <td>{{ item.price }}</td>
    <td>
      <button @click="changNum(-1,index)">-</button>{{ item.num
      }}<button @click="changNum(1,index)">+</button>
    </td>
    <td>{{ item.num * item.price }}</td>
    <td><button @click="$store.commit('goodlist/removeList',index)">删除</button></td>
  </tr>
</template>

<script>
export default {
  props: {
    item: {
      type: Object,
      default: () => ({})
    },
    index: {
      type: Number
    }
  },
  methods: {
    // 加减
    changNum (num, index) {
      const newNum = this.item.num + num
      if (newNum < 1) return
      this.$store.commit('goodlist/changenum', {
        index,
        num: newNum
      })
    }
  }
}
</script>

<style>
</style>
